package com.hmall.item.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfiguration {

    @Bean
    public FanoutExchange fanoutExchange() {
        // return ExchangeBuilder.fanoutExchange("lhr.fanout").build();
        return new FanoutExchange("lhr.fanout");
    }

    @Bean
    public Queue queue1() {
//        return QueueBuilder.durable("lhr.queue1").build();
        return new Queue("lhr.queue1");
    }

    @Bean
    public Queue queue2() {
        return new Queue("lhr.queue2");
    }

    // 按参数名对应，此方法绑定queue1
    @Bean
    public Binding bindQueue1(Queue queue1, FanoutExchange fanoutExchange) {
        // return BindingBuilder.bind(queue1).to(directExchange).with("routingKey");
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    @Bean
    public Binding bindQueue2(Queue queue2, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }

}
